package view.MainWindow;

import Controller.LoginController;
import Controller.UserController;
import view.Interface.window.PublicFatherWindow;

import javax.swing.*;
import java.awt.*;

public class UserMainWindow extends PublicFatherWindow {

    public UserMainWindow(UserController handler) {
        // 设置窗口基本属性
        setTitle("无一烦 - 健康管理大师");
        setSize(1000, 600);
        setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        setLocationRelativeTo(null); // 居中显示

        // 整体使用 BorderLayout
        setLayout(new BorderLayout());

        // ========== 顶部：横向导航栏 + 搜索框 ==========
        JPanel topPanel = new JPanel();
        topPanel.setLayout(new FlowLayout(FlowLayout.LEFT)); // 靠左排列
        topPanel.setBackground(Color.LIGHT_GRAY);

        // 添加几个顶部按钮

        topPanel.add(new JButton("首页"));
        topPanel.add(new JButton("健康档案"));
        topPanel.add(new JButton("我的报告"));
        topPanel.add(new JButton("设置"));

        // 添加搜索框
        JTextField searchField = new JTextField(20);
        JButton searchButton = new JButton("🔍");
        topPanel.add(Box.createHorizontalStrut(20)); // 添加间距
        topPanel.add(searchField);
        topPanel.add(searchButton);

        // ========== 左侧：纵向导航栏 ==========
        JPanel leftPanel = new JPanel();
        leftPanel.setLayout(new BoxLayout(leftPanel, BoxLayout.Y_AXIS));
        leftPanel.setBackground(new Color(240, 240, 240));

        leftPanel.add(new JButton("仪表盘"));
        leftPanel.add(Box.createVerticalStrut(10)); // 加点间距
        leftPanel.add(new JButton("个人信息"));
        leftPanel.add(Box.createVerticalStrut(10));
        leftPanel.add(new JButton("健康记录"));
        leftPanel.add(Box.createVerticalStrut(10));
        leftPanel.add(new JButton("历史记录"));
        leftPanel.setBorder(BorderFactory.createEmptyBorder(10, 10, 10, 10));

        // ========== 右侧：内容展示区 ==========
        JTextArea contentArea = new JTextArea("欢迎使用健康管理系统\n在这里查看您的健康数据");
        contentArea.setEditable(false);
        contentArea.setFont(new Font("微软雅黑", Font.PLAIN, 18));
        JScrollPane contentScrollPane = new JScrollPane(contentArea);

        // ========== 组合左右两部分 ==========
        JSplitPane mainSplitPane = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT);
        mainSplitPane.setLeftComponent(leftPanel);
        mainSplitPane.setRightComponent(contentScrollPane);
        mainSplitPane.setDividerLocation(150); // 左侧宽度
        mainSplitPane.setOneTouchExpandable(true);

        // ========== 整体组合 ==========
        add(topPanel, BorderLayout.NORTH);
        add(mainSplitPane, BorderLayout.CENTER);
    }

    // 主方法启动界面
//    public static void main(String[] args) {
//        SwingUtilities.invokeLater(() -> {
//            new UserMainWindow(new LoginController("User")).open();
//        });
//    }
}